#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
import requests
from base_spider import BaseSpider

class WalmartSpider(BaseSpider):
  def __init__(self, spider):
    super().__init__(spider)

  def getData(self):
    headers = {
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
    }
    req = requests.get(self.url, headers=headers)
    soup = BeautifulSoup(req.text)

    title = soup.find('div', class_='ProductTitle').get_text()
    price = soup.find('span', class_="Price-group").get_text()
    sku = soup.find(attrs={"itemprop" : "sku"}).get('content')
    return {
      'price': price,
      'title': title,
      'sku': sku,
    }

  def setToDb(self):
    super().setToDb('walmart')

# a = WalmartSpider('https://www.walmart.com/ip/Lifestyle-Attitudes-Women-s-Cold-Shoulder-Ruffle-Top/56204498')
# a.getData()